<template>
    <view class="page-wrap">
        <view class="header"></view>
        <view class="box user-box">
            <view class="box-item">
                <view class="user box-fill">
                    <view class="avatar">
                        <image src="../../../static/image/avatar.png"></image>
                    </view>
                    <view class="info" v-if="login">
                        <view class="mobile">{{userInfo.mobile}}</view>
                        <!-- <view class="welcome">欢迎使用</view> -->
                    </view>
                    <view v-else class="to-auth" @click="handleAuth">授权登录</view>
                </view>
                <!-- <u-icon class="box-arrow" name="arrow-right"></u-icon> -->
            </view>
            <view class="box-item" @click="toPage('/pages/person/code')">
                <view class="box-icon">
                    <u-icon :color="color['primary-color']" size="1em" name="scan"></u-icon>
                </view>
                <view class="box-fill">身份码</view>
                <u-icon class="box-arrow" name="arrow-right"></u-icon>
            </view>
            <view class="box-item" @click="toPage('/pages/coupon/takeRecord')">
                <view class="box-icon">
                    <u-icon :color="color['primary-color']" size="1em" name="coupon-fill"></u-icon>
                </view>
                <view class="box-fill">我的优惠券</view>
                <u-icon class="box-arrow" name="arrow-right"></u-icon>
            </view>
        </view>
        <view class="box">
            <view class="box-item" @click="toPage('/pages/main/order')">
                <view class="box-icon">
                    <u-icon :color="color['primary-color']" size="1em" name="order"></u-icon>
                </view>
                <view class="box-fill">配送订单</view>
                <u-icon class="box-arrow" name="arrow-right"></u-icon>
            </view>
            <view class="box-item" @click="toPage('/pages/voucher/order')">
                <view class="box-icon">
                    <u-icon :color="color['primary-color']" size="1em" name="coupon"></u-icon>
                </view>
                <view class="box-fill">兑换券订单</view>
                <u-icon class="box-arrow" name="arrow-right"></u-icon>
            </view>
        </view>
        <view class="box">
            <view class="box-item" @click="toPage('/pages/dormitory/list')">
                <view class="box-icon">
                    <u-icon :color="color['primary-color']" size="1em" name="map"></u-icon>
                </view>
                <view class="box-fill">收货地址</view>
                <u-icon class="box-arrow" name="arrow-right"></u-icon>
            </view>
            <view class="box-item" @click="toPage('/pages/person/shareCode')">
                <view class="box-icon">
                    <u-icon :color="color['primary-color']" size="1em" name="share"></u-icon>
                </view>
                <view class="box-fill">分享码</view>
                <u-icon class="box-arrow" name="arrow-right"></u-icon>
            </view>
            <view class="box-item">
                <view class="box-icon">
                    <u-icon :color="color['primary-color']" size="1em" name="kefu-ermai"></u-icon>
                </view>
                <button class="box-fill contact" open-type="contact">联系客服</button>
                <u-icon class="box-arrow" name="arrow-right"></u-icon>
            </view>
        </view>
        <global-components ref="global-components" :loading="false"></global-components>
    </view>
</template>

<script>
    import {
        mapState,
        mapMutations
    } from 'vuex';
    export default {
        data() {
            return {
                bgColor: '',
                img: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F016a9c5541f138000001714aebe226.jpg%401280w_1l_2o_100sh.png&refer=http%3A%2F%2Fimg.zcool.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1626255194&t=5d2bb7369571c6d2b5e5c78a99a76a92'
            };
        },
        onLoad() {},
        computed: {
            ...mapState(['userInfo', 'login']),
            bgColorStyle() {
                const style = {};
                style.backgroundColor = this.bgColor;
                return style;
            }
        },
        methods: {
            handleAuth() {
                this.$refs['global-components'].showAuth();
            },
            handleGetColors(colors) {
                this.bgColor = colors[0];
                uni.setBackgroundColor({
                    backgroundColorTop: this.bgColor
                });
            },
            toPage(url) {
                if (this.login) {
                    this.$toPage({url});
                } else {
                    this.$refs['global-components'].showAuth();
                }
            },
        }
    };
</script>

<style scoped lang="scss">
    .page-wrap {
        min-height: 100vh;

        .header {
            background-color: $primary-color;
            height: 150rpx;
        }

        .box {
            margin: 32rpx;
            border-radius: 48rpx;
            background-color: #fff;

            &+.box {
                margin-top: 0;
            }

            .box-item {
                display: flex;
                align-items: center;
                margin: 0 32rpx;
                padding: 32rpx 0;
                font-size: 32rpx;
                line-height: 1;

                .box-icon {
                    color: $primary-color;
                    margin-right: 32rpx;
                    font-size: 1.5em;
                }

                .box-fill {
                    flex-grow: 1;
                }

                .box-arrow {
                    color: #cdcdcd;
                }

                &+.box-item {
                    border-top: 1rpx solid #eee;
                }
            }
        }

        .user-box {
            margin-top: -100rpx;

            .user {
                display: flex;
                align-items: center;

                .avatar {
                    width: 130rpx;
                    height: 130rpx;
                    overflow: hidden;
                    border-radius: 50%;
                    margin-right: 32rpx;

                    image {
                        width: 100%;
                        height: 100%;
                    }
                }

                .info {
                    font-size: 32rpx;

                    .welcome {
                        margin-top: 16rpx;
                        font-size: 0.8em;
                        opacity: 0.6;
                    }
                }
            }
        }

        .contact {
            text-align: left;
            padding: 0;
            background: none;
            font-size: 32rpx;
            line-height: 1;

            &::after {
                display: none;
            }
        }

    }
</style>